//
//  LoginViewController.m
//  悟空市场1.0
//
//  Created by 纵情向前 on 2017/3/16.
//  Copyright © 2017年 纵情向前科技有限公司. All rights reserved.
//


#import "AnimatingView.h"
#import "PublicClass.h"
@interface AnimatingView ()@property (nonatomic,strong) UIImageView *imageView;
@property (nonatomic,strong) UIImageView *smallImageView;

@end
@implementation AnimatingView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self addTheAnimation];
    }
    return self;
}

- (void)addTheAnimation{
    
    
    _imageView = [[UIImageView alloc]init];
//    _imageView.frame = CGRectMake(0, 64, MAINSCREEN_WIDTH, ADAPTATION_HEIGHT((667-64)));
    _imageView.bounds = CGRectMake(0, 0, MAINSCREEN_WIDTH/2, MAINSCREEN_WIDTH/2);
    _imageView.center = CGPointMake(MAINSCREEN_WIDTH/2, MAINSCREEN_HEIGHT/2);
    [self addSubview:_imageView];
    /***************图片帧动画**********************/
    NSArray *array = @[@"loding 1_00000",@"loding 1_00001",@"loding 1_00002",@"loding 1_00003",@"loding 1_00004",@"loding 1_00005",@"loding 1_00006",@"loding 1_00007",@"loding 1_00008",@"loding 1_00009",@"loding 1_00010",@"loding 1_00011",@"loding 1_00012",@"loding 1_00013",@"loding 1_00014",@"loding 1_00015",@"loding 1_00016",@"loding 1_00017",@"loding 1_00018",@"loding 1_00019",@"loding 1_00020",@"loding 1_00021",@"loding 1_00022",@"loding 1_00023",@"loding 1_00024",@"loding 1_00025",@"loding 1_00026",@"loding 1_00027",@"loding 1_00028",@"loding 1_00029",@"loding 1_00030",@"loding 1_00031",@"loding 1_00032",@"loding 1_00033",@"loding 1_00034",@"loding 1_00035",@"loding 1_00036",@"loding 1_00037",@"loding 1_00038",@"loding 1_00039",@"loding 1_00040",@"loding 1_00041"];//图片名
    NSMutableArray *images = [NSMutableArray array];//图片
    for (NSString *name in array) {
        [images addObject:[UIImage imageNamed:name]];//分别添加每一个名字对应的image
    }
    _imageView.animationImages = images;//放入多张图
    _imageView.animationDuration = 1;//时间
    _imageView.animationRepeatCount = -1;//重复量不结束


    _smallImageView = [[UIImageView alloc]init];
    _smallImageView.bounds = CGRectMake(0, 0, MAINSCREEN_WIDTH/2, MAINSCREEN_WIDTH/2);
    _smallImageView.center = CGPointMake(MAINSCREEN_WIDTH/2, MAINSCREEN_HEIGHT/2);
    [self addSubview:_smallImageView];
    /***************图片帧动画**********************/
    NSArray *array1 = @[@"loding 1_00000",@"loding 1_00001",@"loding 1_00002",@"loding 1_00003",@"loding 1_00004",@"loding 1_00005",@"loding 1_00006",@"loding 1_00007",@"loding 1_00008",@"loding 1_00009",@"loding 1_00010",@"loding 1_00011",@"loding 1_00012",@"loding 1_00013",@"loding 1_00014",@"loding 1_00015",@"loding 1_00016",@"loding 1_00017",@"loding 1_00018",@"loding 1_00019",@"loding 1_00020",@"loding 1_00021",@"loding 1_00022",@"loding 1_00023",@"loding 1_00024",@"loding 1_00025",@"loding 1_00026",@"loding 1_00027",@"loding 1_00028",@"loding 1_00029",@"loding 1_00030",@"loding 1_00031",@"loding 1_00032",@"loding 1_00033",@"loding 1_00034",@"loding 1_00035",@"loding 1_00036",@"loding 1_00037",@"loding 1_00038",@"loding 1_00039",@"loding 1_00040",@"loding 1_00041",];//图片名
    NSMutableArray *smallImages = [NSMutableArray array];//图片
    for (NSString *name in array1) {
        [smallImages addObject:[UIImage imageNamed:name]];//分别添加每一个名字对应的image
    }
    
    _smallImageView.animationImages = smallImages;//放入多张图
    _smallImageView.animationDuration = 1;//时间
    _smallImageView.animationRepeatCount = -1;//重复量不结束
    
}
//小动画效果

- (void)startTheAnimation{
    [_imageView startAnimating];//开始动画
    
    [[UIApplication sharedApplication].keyWindow addSubview:self.imageView];
    
}
- (void)stopTheAnimation{

   [_imageView stopAnimating];
    
    [self removeFromSuperview];
  
}

//大动画效果

- (void)startTheSmallAnimation{
    [_smallImageView startAnimating];//开始动画
    
    [[UIApplication sharedApplication].keyWindow addSubview:self];
    
}
- (void)stopTheSmallAnimation{
    
    [_smallImageView stopAnimating];
    
    [self removeFromSuperview];
    
    
}



@end
